import React,{Component} from 'react';
import { Table,Form} from 'antd';
import Drawers from './Drawers';
import reqwest from 'reqwest';

class Artical extends Component{
    constructor(props){
        super(props);
        this.state={
          data: [],
          loading: false,
          visible: false
        }
    };
    componentDidMount(){
      this.fetch();
    }

    fetch = () => {
      this.setState({ loading: true });
      reqwest({
        url: 'http://localhost:8007/artical/list',
        method: 'get',
        data: {

        },
        type: 'json',
      }).then((data) => {
        this.setState({
          loading: false,
          data: data.results,
        });
      });
    }
    
    handleClick = (record) => {
      this.getValue.refs.wrappedComponent.init(record);
      this.getValue.refs.wrappedComponent.showDrawer();
    };


    render(){
      
      const pagination = {
        pageSize:8
      }

      const columns = [{
        title: '标题',
        dataIndex: 'title',
        render: (text,record) => <a href="javascript:;" onClick={this.handleClick.bind(this,record)}>{text}</a>,
      },
      {
        title: '作者',
        dataIndex: 'author',
      },
      {
        title: '类型',
        dataIndex: 'type',
      },
      {
        title: '标签',
        dataIndex: 'sign',
      }, {
        title:'创建时间',
        dataIndex:'createtime',
      }
      ,{
        title:'修改时间',
        dataIndex:'updatetime',
      }
    ];
        return(
          
        <div className="essaydiv">
          <Table
                  columns={columns}
                  dataSource={this.state.data}
                  pagination={pagination}
                  loading={this.state.loading}
                  onChange={this.handleTableChange}
                  className="tab"
          />

          <Drawers ref={ref=>this.getValue=ref}/>
        </div>
        )
    }
}

const LoginForm = Form.create({withRef: true})(Artical);
export default LoginForm;